package com.example.demo.until;

import java.io.*;

public class FileCloseTimeOption {
    // 保存 PID 到文件
    public static void saveCloseTimeToFile(File file) {
        long time = System.currentTimeMillis();
        System.out.println(time);
        // 获取当前程序的PID
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file, true))) {
            writer.write(String.valueOf(time)); // 写入 PID
            writer.newLine(); // 换行
            System.out.println("保存时间: " + time);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 从文件中加载 PID
    public static Long loadPidsFromFile(File file) {
        long time = 0;
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            String line;
            if ((line = reader.readLine()) != null){
                time = Long.parseLong(line);
                return time;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return time;
    }


}
